package com.example.demo1.common;

import lombok.Data;

@Data
public class Result {
    private static final int SUCCESS_CODE = 20000;
    private static final int FAIL_CODE = 20005;
    public static final int ALREADY_EXIST_CODE = 30001;

    private int code;
    private String msg;
    private Object data;

    public Result(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static Result success() {
        return new Result(SUCCESS_CODE, "success", null);
    }

    public static Result success(Object data) {
        return new Result(SUCCESS_CODE, "success", data);
    }

    public static Result fail(String msg) {
        return new Result(FAIL_CODE, msg,null);
    }

    /**
     * 传入失败状态码，返回Result结果
     * @param code 失败状态码
     * @param msg 文本提示
     * @return Result结果
     */
    public static Result fail(int code, String msg) {
        return new Result(code, msg, null);
    }

}
